# -*- makefile -*-
# Copyright (c) 2008-2018 Cisco Systems, Inc.  All rights reserved.
# Copyright (c) 2008      Sun Microsystems, Inc.  All rights reserved.
# Copyright (c) 2020      Intel, Inc.  All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#

MD2NROFF = $(OMPI_TOP_SRCDIR)/config/md2nroff.pl

TRIM_OPTIONS=
if ! MAN_PAGE_BUILD_MPIFH_BINDINGS
    TRIM_OPTIONS += --nofortran
endif
if ! MAN_PAGE_BUILD_USEMPIF08_BINDINGS
    TRIM_OPTIONS += --nof08
endif

# JMS This rule can be deleted once all man pages have been converted
# to markdown.
.1in.1:
	$(OMPI_V_GEN) $(top_srcdir)/config/make_manpage.pl \
	  --package-name='@PACKAGE_NAME@' \
	  --package-version='@PACKAGE_VERSION@' \
	  --ompi-date='@OMPI_RELEASE_DATE@' \
	  --opal-date='@OPAL_RELEASE_DATE@' \
	  --input=$< \
	  --output=$@

# JMS This rule can be deleted once all man pages have been converted
# to markdown.
.3in.3:
	$(OMPI_V_GEN) $(top_srcdir)/config/make_manpage.pl \
	  --package-name='@PACKAGE_NAME@' \
	  --package-version='@PACKAGE_VERSION@' \
	  --ompi-date='@OMPI_RELEASE_DATE@' \
	  --opal-date='@OPAL_RELEASE_DATE@' \
	  $(TRIM_OPTIONS) \
	  --input=$< \
	  --output=$@

# JMS This rule can be deleted once all man pages have been converted
# to markdown.
.7in.7:
	$(OMPI_V_GEN) $(top_srcdir)/config/make_manpage.pl \
	  --package-name='@PACKAGE_NAME@' \
	  --package-version='@PACKAGE_VERSION@' \
	  --ompi-date='@OMPI_RELEASE_DATE@' \
	  --opal-date='@OPAL_RELEASE_DATE@' \
	  --input=$< \
	  --output=$@

%.1: %.1.md
	$(OMPI_V_GEN) $(MD2NROFF) --source=$< --dest=$@ --pandoc=$(PANDOC)

%.3: %.3.md
	$(OMPI_V_GEN) $(MD2NROFF) --source=$< --dest=$@ --pandoc=$(PANDOC)

%.5: %.5.md
	$(OMPI_V_GEN) $(MD2NROFF) --source=$< --dest=$@ --pandoc=$(PANDOC)

%.7: %.7.md
	$(OMPI_V_GEN) $(MD2NROFF) --source=$< --dest=$@ --pandoc=$(PANDOC)

# It is an error to "configure --disable-man-pages" and then try to
# "make dist".
if !OPAL_ENABLE_MAN_PAGES
dist-hook:
	@echo "************************************************************************************"
	@echo "ERROR: 'make dist' inoperable when Open MPI is configured with --disable-man-pages"
	@echo "************************************************************************************"
	@/bin/false
endif

# A little verbosity magic; "make" will show the terse output.  "make
# V=1" will show the actual commands used (just like the other
# Automake-generated compilation/linker rules).
V=0

OMPI_V_LN_S = $(ompi__v_LN_S_$V)
ompi__v_LN_S_ = $(ompi__v_LN_S_$AM_DEFAULT_VERBOSITY)
ompi__v_LN_S_0 = @echo "  LN_S    " `basename $@`;

OMPI_V_MKDIR = $(ompi__v_MKDIR_$V)
ompi__v_MKDIR_ = $(ompi__v_MKDIR_$AM_DEFAULT_VERBOSITY)
ompi__v_MKDIR_0 = @echo "  MKDIR   " $@;

OMPI_V_GEN = $(ompi__v_GEN_$V)
ompi__v_GEN_ = $(ompi__v_GEN_$AM_DEFAULT_VERBOSITY)
ompi__v_GEN_0 = @echo "  GENERATE" $@;
